package com.ics.web.controller.travelstar.controller;

import com.ics.common.core.domain.AjaxResult;
import com.ics.web.controller.travelstar.domain.IndexBanner;
import com.ics.web.controller.travelstar.service.ITbIndexBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shaoly
 * @description
 * @ClassName IndexController.java
 * @createTime 2024年09月04日 16:16:17
 */
@RestController
@RequestMapping("/index")
@Api(value = "首页", tags = "首页接口")
public class IndexController {

    @Resource
    private ITbIndexBannerService bannerService;

    /**
     * 首页banner图接口
     */
    @ApiOperation("首页banner图接口")
    @GetMapping("/getIndexBanner/{type}")
    public AjaxResult getIndexBanner(@PathVariable String type) {
        List<IndexBanner> bannerList = bannerService.lambdaQuery()
                .eq(IndexBanner::getPicType, type)
                .orderByDesc(IndexBanner::getCreateTime)
                .list();
        return AjaxResult.success(bannerList);
    }


    /**
     * banner图新增
     */
    @ApiOperation("banner信息新增")
    @PostMapping("/addIndexBanner")
    public AjaxResult addIndexBanner(@RequestBody IndexBanner banner) {
        return AjaxResult.success(bannerService.saveOrUpdate(banner));
    }


    /**
     * banner信息删除
     * @param id
     * @return
     */
    @ApiOperation("banner信息删除")
    @PostMapping("/delIndexBanner/{id}")
    public AjaxResult delIndexBanner(@PathVariable String id) {
        return AjaxResult.success(bannerService.removeById(id));
    }



}
